package com.aspectj.aop.aspects;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

/**
 * desc   : 异常捕获AOP
 * author : chendaning
 * date   : 6/11/21
 */
@Aspect
public class TryCatchAspect extends FatherAspect{
    private final String POINTCUT = "execution(@com.aspectj.aop.annotation.TryCatch * *(..))";

    @Pointcut(POINTCUT)
    public void onTryCatchPointcut() {}

    /**
     * @param joinPoint
     * @return
     * @throws Throwable
     */
    @Around("onTryCatchPointcut()")
    public Object execute(ProceedingJoinPoint joinPoint) throws Throwable {
        logger("exe TryCatch");
        Object result = null;
        try {
            result = joinPoint.proceed();
        } catch (Exception e) {
            logger("exe TryCatch ERROR=" + e.toString());
        }
        return result;
    }

}